package com.kaily.timemanager.db;

import android.content.Context;
import android.graphics.drawable.Drawable;

import rx.Observable;
import rx.Observer;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by zhoulikai on 17/3/3.
 * 本地数据异步处理
 */

public class AppLocalDataClient {

    private static AppLocalDataClient appLocalDataClient;
    private Context context;

    private AppLocalDataClient(Context context) {
        this.context = context;
    }

    public static AppLocalDataClient getInstance(Context context) {
        if (appLocalDataClient == null) {
            appLocalDataClient = new AppLocalDataClient(context);
        }
        return appLocalDataClient;
    }

    public void request(Observable.OnSubscribe onSubscribe, Subscriber subscriber) {
        Observable.create(onSubscribe)
                .subscribeOn(Schedulers.io()) // 指定 subscribe() 发生在 IO 线程
                .observeOn(AndroidSchedulers.mainThread()) // 指定 Subscriber 的回调发生在主线程
                .subscribe(subscriber);
    }


}
